package com.dyz.leetcode._05_sort;

import java.util.Arrays;
import java.util.Comparator;

public class comparator_sort {


    public static void main(String[] args) {
        Persion p1 = new Persion("1", 31);
        Persion p2 = new Persion("2", 1);
        Persion p3 = new Persion("3", 21);
        Persion p4 = new Persion("4", 8);
        Persion[] p = new Persion[]{p1, p2, p3, p4};
        Comparator<Persion> comparator = (o1, o2)->o1.getAge()-o2.getAge();
        Comparator<Persion> comparator1 = new Comparator<Persion>() {
            @Override
            public int compare(Persion o1, Persion o2) {
                return o1.getAge()-o2.getAge();
            }
        };
//        Arrays.sort(p, new Comparator<Persion>() {
//            @Override
//            public int compare(Persion o1, Persion o2) {
//                return o1.getAge()-o2.getAge();
//            }
//        });
        Arrays.sort(p, comparator);
        System.out.println(Arrays.toString(p));
    }


}
